{% extends "base.html" %}
{% block title %}我的帖子 - Online Judge{% endblock %}

{% block content %}
<div class="max-w-7xl mx-auto py-8 px-4 sm:px-6 lg:px-8">
  <!-- 页面标题 -->
  <div class="mb-8">
    <h1 class="text-3xl font-bold text-gray-800 flex items-center">
      <i class="fas fa-user-edit text-blue-600 mr-3"></i>
      我的帖子
    </h1>
    <p class="mt-2 text-gray-500">查看和管理您发布的所有论坛帖子</p>
  </div>

  <!-- 帖子列表 -->
  <div class="space-y-6">
    {% if posts.items %}
      {% for post in posts.items %}
        <div class="bg-white rounded-xl shadow-sm hover:shadow-md transition-shadow duration-300 overflow-hidden border-t-2 border-transparent hover:border-blue-200 transition-colors">
          <div class="p-6">
            <!-- 标题与元信息 -->
            <div class="flex flex-col sm:flex-row sm:justify-between sm:items-start mb-4">
              <div>
                <h2 class="text-xl font-semibold">
                  <a href="{{ url_for('forum_post', post_id=post.id) }}" class="text-blue-600 hover:text-blue-800 transition-colors">
                    {{ post.title }}
                  </a>
                </h2>
                <div class="flex items-center mt-2 text-sm text-gray-500 space-x-3">
                  <span>
                    <i class="fas fa-clock text-gray-400 mr-1"></i>
                    发布于：{{ post.created_at.strftime('%Y-%m-%d %H:%M') }}
                  </span>
                  {% if post.is_pinned %}
                    <span class="inline-block bg-yellow-100 text-yellow-600 px-2 py-1 rounded-md text-xs font-medium">
                      <i class="fas fa-thumbtack mr-1"></i> 置顶
                    </span>
                  {% endif %}
                </div>
              </div>
            </div>

            <!-- 内容预览 -->
            <p class="text-gray-700 leading-relaxed mb-6">
              {{ post.content|truncate(150) }}
              {% if post.content|length > 150 %}
                <a href="{{ url_for('forum_post', post_id=post.id) }}" class="text-blue-600 hover:underline text-sm font-medium mt-2 inline-block">
                  查看完整内容 <i class="fas fa-chevron-right ml-1"></i>
                </a>
              {% endif %}
            </p>

            <!-- 互动数据 -->
            <div class="flex items-center justify-between text-gray-500">
              <div class="flex items-center space-x-6">
                <span class="flex items-center space-x-1">
                  <i class="fas fa-thumbs-up text-gray-400"></i>
                  <span>{{ post.likes|length }}</span>
                </span>
                <span class="flex items-center space-x-1">
                  <i class="fas fa-comment text-gray-400"></i>
                  <span>{{ post.comments|length }}</span>
                </span>
              </div>

              <!-- 操作按钮（示例，需根据权限控制） -->
              <div class="flex space-x-2">
                <a href="{{ url_for('edit_post', post_id=post.id) }}" class="text-blue-500 hover:underline">
                  <i class="fas fa-pencil mr-1"></i> 编辑
                </a>
                <form method="POST" action="{{ url_for('delete_post', post_id=post.id) }}" class="inline">
                  <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                  <button type="submit" class="text-red-500 hover:underline" onclick="return confirm('确定删除该帖子？')">
                    <i class="fas fa-trash mr-1"></i> 删除
                  </button>
                </form>
              </div>
            </div>
          </div>
        </div>
      {% endfor %}
    {% else %}
      <!-- 空状态 -->
      <div class="text-center py-12 bg-gray-50 rounded-lg border border-gray-100">
        <div class="inline-flex items-center justify-center w-16 h-16 rounded-full bg-blue-100 mb-6">
          <i class="fas fa-file-alt text-2xl text-blue-600"></i>
        </div>
        <h3 class="text-lg font-medium text-gray-900 mb-2">您还没有发布任何帖子</h3>
        <p class="max-w-md mx-auto text-gray-500">
          可以前往论坛分享您的见解、提问或经验，与社区互动交流。
        </p>
        <a href="{{ url_for('forum_audit') }}" class="mt-6 inline-flex items-center px-4 py-2 border border-transparent text-sm font-medium rounded-lg shadow-sm text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 transition-all duration-200">
          <i class="fas fa-plus mr-2"></i> 发布新帖
        </a>
      </div>
    {% endif %}
  </div>

  <!-- 分页导航 -->
  {% if posts.pages > 1 %}
    <div class="mt-8 flex justify-center">
      <nav class="inline-flex items-center space-x-2">
        <!-- 上一页 -->
        {% if posts.has_prev %}
          <a href="{{ url_for('user_posts', page=posts.prev_num) }}" class="px-4 py-2 bg-white border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 transition-colors">
            <i class="fas fa-chevron-left mr-1"></i> 上一页
          </a>
        {% else %}
          <span class="px-4 py-2 bg-gray-50 border border-gray-300 rounded-md text-gray-400 cursor-not-allowed">
            <i class="fas fa-chevron-left mr-1"></i> 上一页
          </span>
        {% endif %}

        <!-- 页码信息 -->
        <span class="px-4 py-2 text-gray-500">
          第 {{ posts.page }} 页 / 共 {{ posts.pages }} 页
        </span>

        <!-- 下一页 -->
        {% if posts.has_next %}
          <a href="{{ url_for('user_posts', page=posts.next_num) }}" class="px-4 py-2 bg-white border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 transition-colors">
            下一页 <i class="fas fa-chevron-right ml-1"></i>
          </a>
        {% else %}
          <span class="px-4 py-2 bg-gray-50 border border-gray-300 rounded-md text-gray-400 cursor-not-allowed">
            下一页 <i class="fas fa-chevron-right ml-1"></i>
          </span>
        {% endif %}
      </nav>
    </div>
  {% endif %}
</div>
{% endblock %}